package yto.freemarker.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import yto.freemarker.springcloud.entity.User;
import yto.freemarker.springcloud.feign.UserFeignClient;

/**
 * @author dongxing
 * @create 2017-12-24 17:00
 **/
@RestController
public class UserController {
    @Autowired
    private UserFeignClient userFeignClient;

//    @GetMapping("/simple/{id}")
//    public User findById(@PathVariable Long id) {
//        return userFeignClient.findById(id);
//    }
//
//    @GetMapping("/test")
//    public User testPost(User user) {
//        return userFeignClient.posetUser(user);
//    }
//
//
//    @GetMapping("/test-get")
//    public User testGet(User user) {
//        return this.userFeignClient.getUser(user.getUsername(),user.getAge());
//    }

    /**
     * 采用的是压缩的方式
     *
     * @param id
     * @return
     */
    @GetMapping("/simple/{id}")
    public String findById(@PathVariable Long id) {
        return new String(userFeignClient.findById(id).getBody());
    }

    @GetMapping("/test")
    public String testPost(User user) {
        return new String(userFeignClient.posetUser(user).getBody());
    }


    @GetMapping("/test-get")
    public String testGet(User user) {
        return new String(this.userFeignClient.getUser(user.getUsername(), user.getAge()).getBody());
    }


}
